package cn.tedu.egcar1.controller;

import cn.tedu.egcar1.base.response.JsonResult;
import cn.tedu.egcar1.mapper.VehicleMapper;
import cn.tedu.egcar1.pojo.dto.VehicleAddParam;
import cn.tedu.egcar1.pojo.dto.VehicleListQuery;
import cn.tedu.egcar1.pojo.entity.Vehicle;
import cn.tedu.egcar1.pojo.vo.VehicleListVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.PanelUI;
import java.util.Date;
import java.util.List;

@Slf4j
@Tag(name="车辆管理")
@RestController
@RequestMapping("/v1/vehicle/")
public class VehicleController {
    @Autowired
    private VehicleMapper vehicleMapper;


    @PostMapping("add")
    @Operation(summary = "添加车辆")
    @ApiOperationSupport(order=10)
    public JsonResult addVehicle(@RequestBody VehicleAddParam param){
        log.debug("车俩信息："+param);
        Vehicle vehicle=new Vehicle();
        BeanUtils.copyProperties(param,vehicle);
        vehicle.setCreate_time(new Date());
        vehicle.setUpdate_time(new Date());
        vehicle.setUser_id(101L);
        vehicleMapper.insertVehicle(vehicle);
        return JsonResult.OK();
    }


    @GetMapping("list")
    @Operation(summary = "查询车辆列表")
    @ApiOperationSupport(order=20)
    public JsonResult listVehicle(@RequestBody VehicleListQuery query){
         log.debug("查询参数："+query);
        List<VehicleListVO> vehicleList=vehicleMapper.vehicleqeury(query);
        return JsonResult.OK(vehicleList);
    }

    @PostMapping("delete")
    @Operation(summary="删除车辆")
    @ApiOperationSupport(order=30)
    public JsonResult deleteVehicle(Long id){
        log.debug("车辆编码："+id);
        vehicleMapper.deleleVehicle(id);
        return JsonResult.OK();
    }



}
